from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-16 14:27:34.405868
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 16, Jan, 2021
Time: 14:27:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.1799
Nobs: 173.000 HQIC: -46.1548
Log likelihood: 1930.67 FPE: 4.64185e-21
AIC: -46.8203 Det(Omega_mle): 2.79928e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.455440 0.148697 3.063 0.002
L1.Burgenland 0.134756 0.077072 1.748 0.080
L1.Kärnten -0.235696 0.062571 -3.767 0.000
L1.Niederösterreich 0.138269 0.178873 0.773 0.440
L1.Oberösterreich 0.230250 0.153041 1.505 0.132
L1.Salzburg 0.178006 0.080983 2.198 0.028
L1.Steiermark 0.079108 0.110665 0.715 0.475
L1.Tirol 0.157191 0.073429 2.141 0.032
L1.Vorarlberg 0.015979 0.070024 0.228 0.819
L1.Wien -0.138166 0.148828 -0.928 0.353
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.520149 0.189834 2.740 0.006
L1.Burgenland 0.014488 0.098395 0.147 0.883
L1.Kärnten 0.372472 0.079881 4.663 0.000
L1.Niederösterreich 0.132814 0.228359 0.582 0.561
L1.Oberösterreich -0.180367 0.195379 -0.923 0.356
L1.Salzburg 0.177295 0.103387 1.715 0.086
L1.Steiermark 0.241737 0.141280 1.711 0.087
L1.Tirol 0.145972 0.093743 1.557 0.119
L1.Vorarlberg 0.189997 0.089396 2.125 0.034
L1.Wien -0.600288 0.190001 -3.159 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295487 0.065846 4.488 0.000
L1.Burgenland 0.109379 0.034129 3.205 0.001
L1.Kärnten -0.022981 0.027708 -0.829 0.407
L1.Niederösterreich 0.059849 0.079208 0.756 0.450
L1.Oberösterreich 0.279982 0.067769 4.131 0.000
L1.Salzburg 0.002342 0.035861 0.065 0.948
L1.Steiermark -0.017339 0.049004 -0.354 0.723
L1.Tirol 0.096282 0.032516 2.961 0.003
L1.Vorarlberg 0.126074 0.031008 4.066 0.000
L1.Wien 0.076672 0.065904 1.163 0.245
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209098 0.077625 2.694 0.007
L1.Burgenland -0.005724 0.040235 -0.142 0.887
L1.Kärnten 0.025203 0.032664 0.772 0.440
L1.Niederösterreich 0.030448 0.093378 0.326 0.744
L1.Oberösterreich 0.384297 0.079893 4.810 0.000
L1.Salzburg 0.093609 0.042276 2.214 0.027
L1.Steiermark 0.186812 0.057771 3.234 0.001
L1.Tirol 0.044358 0.038333 1.157 0.247
L1.Vorarlberg 0.100344 0.036555 2.745 0.006
L1.Wien -0.070789 0.077694 -0.911 0.362
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.564294 0.154278 3.658 0.000
L1.Burgenland 0.075769 0.079965 0.948 0.343
L1.Kärnten 0.005423 0.064919 0.084 0.933
L1.Niederösterreich -0.013376 0.185586 -0.072 0.943
L1.Oberösterreich 0.132637 0.158784 0.835 0.404
L1.Salzburg 0.046708 0.084022 0.556 0.578
L1.Steiermark 0.109745 0.114818 0.956 0.339
L1.Tirol 0.226330 0.076185 2.971 0.003
L1.Vorarlberg 0.017883 0.072652 0.246 0.806
L1.Wien -0.150641 0.154413 -0.976 0.329
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162134 0.109104 1.486 0.137
L1.Burgenland -0.022807 0.056550 -0.403 0.687
L1.Kärnten -0.011232 0.045910 -0.245 0.807
L1.Niederösterreich 0.179176 0.131245 1.365 0.172
L1.Oberösterreich 0.377643 0.112290 3.363 0.001
L1.Salzburg -0.032295 0.059420 -0.544 0.587
L1.Steiermark -0.046418 0.081198 -0.572 0.568
L1.Tirol 0.196902 0.053877 3.655 0.000
L1.Vorarlberg 0.048356 0.051379 0.941 0.347
L1.Wien 0.155902 0.109199 1.428 0.153
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219490 0.137891 1.592 0.111
L1.Burgenland 0.070135 0.071472 0.981 0.326
L1.Kärnten -0.047976 0.058024 -0.827 0.408
L1.Niederösterreich -0.037072 0.165875 -0.223 0.823
L1.Oberösterreich -0.095256 0.141919 -0.671 0.502
L1.Salzburg 0.029242 0.075098 0.389 0.697
L1.Steiermark 0.375384 0.102623 3.658 0.000
L1.Tirol 0.511462 0.068093 7.511 0.000
L1.Vorarlberg 0.192578 0.064936 2.966 0.003
L1.Wien -0.216342 0.138013 -1.568 0.117
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.101291 0.161512 0.627 0.531
L1.Burgenland 0.015943 0.083715 0.190 0.849
L1.Kärnten -0.104710 0.067964 -1.541 0.123
L1.Niederösterreich 0.230889 0.194289 1.188 0.235
L1.Oberösterreich 0.022844 0.166230 0.137 0.891
L1.Salzburg 0.222153 0.087962 2.526 0.012
L1.Steiermark 0.139051 0.120202 1.157 0.247
L1.Tirol 0.095772 0.079757 1.201 0.230
L1.Vorarlberg 0.020455 0.076059 0.269 0.788
L1.Wien 0.264361 0.161654 1.635 0.102
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.595897 0.087666 6.797 0.000
L1.Burgenland -0.021114 0.045439 -0.465 0.642
L1.Kärnten -0.001581 0.036890 -0.043 0.966
L1.Niederösterreich -0.017837 0.105457 -0.169 0.866
L1.Oberösterreich 0.273524 0.090227 3.032 0.002
L1.Salzburg 0.009310 0.047744 0.195 0.845
L1.Steiermark 0.003224 0.065244 0.049 0.961
L1.Tirol 0.078857 0.043291 1.822 0.069
L1.Vorarlberg 0.168311 0.041284 4.077 0.000
L1.Wien -0.083134 0.087743 -0.947 0.343
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.149343 -0.008081 0.211030 0.254278 0.065851 0.083960 -0.067324 0.154173
Kärnten 0.149343 1.000000 0.004318 0.193293 0.156700 -0.128517 0.162664 0.028961 0.303751
Niederösterreich -0.008081 0.004318 1.000000 0.290723 0.084194 0.218085 0.105543 0.058364 0.354575
Oberösterreich 0.211030 0.193293 0.290723 1.000000 0.293129 0.314701 0.087552 0.079075 0.123432
Salzburg 0.254278 0.156700 0.084194 0.293129 1.000000 0.156594 0.068904 0.078306 -0.023877
Steiermark 0.065851 -0.128517 0.218085 0.314701 0.156594 1.000000 0.100152 0.090717 -0.119683
Tirol 0.083960 0.162664 0.105543 0.087552 0.068904 0.100152 1.000000 0.146636 0.132911
Vorarlberg -0.067324 0.028961 0.058364 0.079075 0.078306 0.090717 0.146636 1.000000 0.094982
Wien 0.154173 0.303751 0.354575 0.123432 -0.023877 -0.119683 0.132911 0.094982 1.000000